package com.lotter.common.enumobject;

import com.lotter.common.util.StringUtil;

//半场
public enum HalfCourtEnum {

	
	 HC_1(1, "胜胜", 3 ,3),
	 HC_2(2, "胜平" ,3 ,1),
	 HC_3(3, "胜负" ,3 ,0),
	 HC_4(4, "平胜" ,1 ,3),
	 HC_5(5, "平平" ,1 ,1),
	 HC_6(6, "平负" ,1 ,0),
	 HC_7(7, "负胜" ,0 ,3),
	 HC_8(8, "负平" ,0 ,1),
	 HC_9(9, "负负" ,0 ,0);

	private int code;
	
	private String desc;
	
    private int harf ;

    private int fina ;

	public int getCode() {
		return code;
	}

	public String getDesc() {
		return desc;
	}
	
	
	/**
	 * @param code the code to set
	 */
	public void setCode(int code) {
		this.code = code;
	}

	/**
	 * @param desc the desc to set
	 */
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
	

	/**
	 * @return the harf
	 */
	public int getHarf() {
		return harf;
	}

	/**
	 * @param harf the harf to set
	 */
	public void setHarf(int harf) {
		this.harf = harf;
	}

	/**
	 * @return the fina
	 */
	public int getFina() {
		return fina;
	}

	/**
	 * @param fina the fina to set
	 */
	public void setFina(int fina) {
		this.fina = fina;
	}

	
	private HalfCourtEnum(int code, String desc, int harf, int fina) {
		this.code = code;
		this.desc = desc;
		this.harf = harf;
		this.fina = fina;
	}

	
	public static Integer judgeCode(String final_score,String first_half){
		if(StringUtil.isBlank(final_score) || StringUtil.isBlank(first_half)){
			return null;
		}
		Integer code =null;
		int num_h = 0 ;
		String[] halfScore = first_half.split(":");
		int home_h = Integer.parseInt(halfScore[0]);
		int away_h = Integer.parseInt(halfScore[1]);
		if(home_h > away_h){
			num_h = 3 ;
		}else if(home_h == away_h){
			num_h = 1 ;
		}else{
			num_h = 0 ;
		}
		
		
		int num_f = 0 ;
		String[] finalScore = final_score.split(":");
		int home_f = Integer.parseInt(finalScore[0]);
		int away_f = Integer.parseInt(finalScore[1]);
		
		if(home_f > away_f){
			num_f = 3 ;
		}else if(home_f == away_f){
			num_f = 1 ;
		}else{
			num_f = 0 ;
		}
		
		for (HalfCourtEnum type : values()) {
			if(type.getHarf() == num_h && type.getFina() ==num_f){
				code = type.getCode();
				break;
			}
		}
		return code ;
	}
	
	


	
}
